// ** React Imports
import { useEffect, useRef } from 'react'
import * as echarts from 'echarts'

const LeftThree = () => {
  const charRef = useRef(null)
  const data = [
    { value: 0.39, name: '一号产线' },
    { value: 0.27, name: '二号产线' },
    { value: 0.18, name: '三号产线' },
    { value: 0.32, name: '四号产线' },
    { value: 0.09, name: '五号产线' },
    { value: 0.1, name: '六号产线' },
  ]

  useEffect(() => {
    initChart()
  }, [])

  const initChart = () => {
    const chart = echarts.init(charRef.current)
    chart.setOption({
      tooltip: {
        trigger: 'item',
      },
      legend: {
        left: '0%',
        top: '0%',
        bottom: '0%',
        orient: 'vertical',
        textStyle: {
          color: '#fff',
        },
      },
      series: [
        {
          name: 'Access From',
          type: 'pie',
          radius: ['30%', '60%'],
          avoidLabelOverlap: false,
          center: ['70%', '65%'],
          label: {
            show: false,
            position: 'center',
          },
          emphasis: {
            label: {
              show: true,
              fontSize: 40,
              fontWeight: 'bold',
            },
          },
          labelLine: {
            show: false,
          },
          data,
        },
      ],
    })
  }
  return (
    <div className="left-two">
      <div className="box-title">设备故障率（每月）</div>
      <div className="box-content left-three-content  dis-flex">
        <div
          className="char flex1"
          ref={charRef}
          style={{ height: '100%', width: '60%' }}
        ></div>
        <div className="category-list flex1 dis-flex">
          <div className="category-item line">
            <div className="category-title">
              <div className="key">一号产线</div>
              <div className="value">39%</div>
            </div>
            <div className="category-title">
              <div className="key">二号产线</div>
              <div className="value">27%</div>
            </div>
            <div className="category-title">
              <div className="key">三号产线</div>
              <div className="value">18%</div>
            </div>
          </div>
          <div className="category-item">
            <div className="category-title">
              <div className="key">四号产线</div>
              <div className="value">32%</div>
            </div>
            <div className="category-title">
              <div className="key">五号产线</div>
              <div className="value">9%</div>
            </div>
            <div className="category-title">
              <div className="key">六号产线</div>
              <div className="value">10%</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  )
}

export default LeftThree
